import React from 'react';
import TYPE from '@design/constant/component-type';
import { Text, Image, Calculate, Divider } from './component';

export default function(options = {}) {
  const { injectProps } = options;
  return {
    renderBlock: (props, editor, next) => {
      const { type } = props.node;
      const newProps = injectProps(props);
      switch (type) {
        case TYPE.TEXT:
          return <Text {...newProps} editor={editor} />;
        case TYPE.IMAGE:
          return <Image {...newProps} />;
        case TYPE.CALCULATE:
          return <Calculate {...newProps} />;
        case TYPE.DIVIDER:
          return <Divider {...newProps} />;
        default:
          return next();
      }
    },
  };
}
